package com.zmx.patients.view.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.zmx.patients.BaseActivity;
import com.zmx.patients.R;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.DecimalFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * 程序猿：胖胖祥
 * 时 间：2020/10/10  23:48
 * 功 能：舌苔问诊结果
 */

public class TongueCoatingResultsActivity extends BaseActivity {

    @BindView(R.id.she_head)
    ImageView sheHead;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.textview_a)
    TextView textviewA;
    @BindView(R.id.textview_b)
    TextView textviewB;
    @BindView(R.id.textview_c)
    TextView textviewC;
    @BindView(R.id.textview_d)
    TextView textviewD;
    @BindView(R.id.textview_e)
    TextView textviewE;
    @BindView(R.id.textview_f)
    TextView textviewF;
    @BindView(R.id.text_a)
    TextView textA;
    @BindView(R.id.text_b)
    TextView textB;
    @BindView(R.id.text_c)
    TextView textC;
    @BindView(R.id.text_d)
    TextView textD;
    @BindView(R.id.text_e)
    TextView textE;
    @BindView(R.id.text_f)
    TextView textF;
    @BindView(R.id.text_g)
    TextView textG;
    @BindView(R.id.text_h)
    TextView textH;
    @BindView(R.id.text_i)
    TextView textI;
    @BindView(R.id.text_j)
    TextView textJ;

    private String data;

    @Override
    protected int getLayoutId() {

        return R.layout.activity_tongue_coating_results;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
        setToolbar(R.id.tool_bar);

        Intent intent = getIntent();
        data = intent.getStringExtra("data");


        time.setText("检测时间：" + simpleDateFormat.format(new Date()));

        if (intent != null) {

            Bitmap bitmap = intent.getParcelableExtra("bitmap");
            sheHead.setImageBitmap(bitmap);

        }

        JSONObject object = null;

        try {

            object = new JSONObject(data);
            JSONObject tiaoli = object.getJSONObject("tiaoli");
            textviewA.setText(tiaoli.getString("tizhi_name"));
            textviewB.setText(tiaoli.getString("changjianbiaoxian"));
            textviewC.setText(tiaoli.getString("fabingqingxiang"));
            textviewD.setText(tiaoli.getString("sijiyangsheng"));
            textviewE.setText(tiaoli.getString("tiyuduanlian"));
            textviewF.setText(tiaoli.getString("shiliao"));

            JSONObject tizhi = object.getJSONObject("tizhi");
            DecimalFormat df = new DecimalFormat("0.00");
            textA.setText(df.format(tizhi.getDouble("xueyu"))+"");
            textB.setText(df.format(tizhi.getDouble("pinghe"))+"");
            textC.setText(df.format(tizhi.getDouble("qixu"))+"");
            textD.setText(df.format(tizhi.getDouble("yangxu"))+"");
            textE.setText(df.format(tizhi.getDouble("shire"))+"");
            textF.setText(df.format(tizhi.getDouble("tanshi"))+"");
            textG.setText(df.format(tizhi.getDouble("tebing"))+"");
            textH.setText(df.format(tizhi.getDouble("qiyu"))+"");
            textI.setText(df.format(tizhi.getDouble("yangxu"))+"");
            textJ.setText(df.format(tizhi.getDouble("xueyu"))+"");


        } catch (JSONException e) {
            e.printStackTrace();
        }


    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
